﻿using BaseUtils.Helper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq.Expressions;

namespace DatabaseCore.Json
{

    public class JsonHelper
    {

        public List<T> Query<T>(Expression<Func<T, bool>> whereExpression) where T : class, new()
        {
            throw new NotImplementedException();
        }

        public string Query(string pt, string stationName, string materialName)
        {
            throw new NotImplementedException();
        }

        public List<T> QueryAll<T>() where T : class, new()
        {
            throw new NotImplementedException();
        }

        public static string baseLogPath = "D:\\ModuleTighten\\Log";

        public static string FindText(string path)
        {
            if (!File.Exists(path))
            {
                return string.Empty;
            }

            return File.ReadAllText(path);
        }

        public static string[] FindTextLines(string path)
        {
            if (!File.Exists(path))
            {
                return new string[] { };
            }
            return File.ReadAllLines(path);
        }

        public static int AppendText(string title, string Contert)
        {
            if (string.IsNullOrEmpty(Contert))
            {
                return 0;
            }
            try
            {
                string dirPath = Path.Combine(baseLogPath, $"{DateTime.Now:'yyyyMMdd'}");
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }
                var fileName = $"{title}.txt";
                var filePath = Path.Combine(dirPath, fileName);
                File.AppendAllText(filePath, $"{Contert}\r\n");
            }
            catch (Exception)
            {

            }
            return 1;
        }
    }
}
